<?php

namespace app\models\search;

use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\BuyerCashback;

/**
 * BuyerCashbackSearch represents the model behind the search form of `app\models\BuyerCashback`.
 */
class BuyerCashbackSearch extends BuyerCashback
{
    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['id', 'uid', 'buyer_id', 'auth_shop_id', 'auth_order_id', 'return_fee', 'ctime', 'state'], 'integer'],
            [['order_no', 'content', 'user_account', 'user_realname'], 'safe'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = BuyerCashback::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'uid' => $this->uid,
            'buyer_id' => $this->buyer_id,
            'auth_shop_id' => $this->auth_shop_id,
            'auth_order_id' => $this->auth_order_id,
            'return_fee' => $this->return_fee,
            'ctime' => $this->ctime,
            'state' => $this->state,
        ]);

        $query->andFilterWhere(['like', 'order_no', $this->order_no])
            ->andFilterWhere(['like', 'content', $this->content])
            ->andFilterWhere(['like', 'user_account', $this->user_account])
            ->andFilterWhere(['like', 'user_realname', $this->user_realname]);

        return $dataProvider;
    }
}
